home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Grafik / Misc / ImageEnginer / ARexx / Batch / BatchConvert.ieb < prev    next >
Encoding:
Text File  |  1997-02-02  |  6.2 KB  |  207 lines

  1. /*
  2. ** $VER: BatchConvert.ieb 1.31, IE Arexx script
  3. ** Image Engineer Batch Processing script
  4. ** Copyright © by Patrik M Nydensten
  5. ** 25/1 1997 Stockholm/Sweden
  6. **
  7. ** Convert all selected images to a user selected file format.
  8. */
  9.  
  10. options results
  11. signal on error
  12.  
  13. parse arg input command
  14. input = upper(strip(input))
  15. address 'IMAGEENGINEER'
  16.  
  17. select  /* Required batch script commands */
  18.   when input = 'INFO' then    return get_info()
  19.   when input = 'CONFIG' then  return get_config(command)
  20.   when input = 'PROCESS' then return process_image(command)
  21.   otherwise do
  22.     'REQUEST' '"Failure in call to batch script!"' '" Quit "'
  23.     return '<ERROR>'
  24.   end
  25. end
  26.  
  27. exit 0
  28.  
  29. /* Required "Get_info" procedure  ------------------------------------ */
  30. /* S = SECONDARY, A = ALPHA, 1 = Single file, 2 = Multiple files       */
  31.  
  32. get_info:
  33.   back = 'OK'
  34. return back
  35.  
  36. /* Required "Get_config" procedure  ---------------------------------- */
  37.  
  38. get_config:
  39.   parse arg '"'command'"'
  40.  
  41.   'IE_TO_FRONT'
  42.  
  43.   /* Unchanged config, only picked for first image */
  44.  
  45.   form = 'FORM "BatchConvert" " OK | Cancel "'
  46.  
  47.   if command = '' then do
  48.     'GET_FILE_TYPE "Select destination file format."'
  49.     if (RC ~= 0) then return '<ERROR>'
  50.     FileType = result
  51.  
  52.     'REQUEST' '"Would you like to save as rendered or 24bit images?"' '" Render | 24bit "'
  53.     qrender = result
  54.  
  55.     if qrender = 1 then do
  56.       'RENDER_GET' '"Set render options."' '0 135168 8 256 1 0'
  57.       if (RC ~= 0) then return '<ERROR>'
  58.       RenderOptions = result
  59.  
  60.       if word(RenderOptions,5) = 0 then form = form||' FILE,"Lock-Palette","IE:Palettes/"'
  61.  
  62.       form = form||' CHECKBOX,"Show rendering in foreground?",1'
  63.     end
  64.  
  65.     form = form||' CHECKBOX,"Strip last non-number suffix?",0',
  66.     ' STRING,"New file suffix","'word(FileType,1)'",10'
  67.  
  68.     form
  69.     parse var result ok rest
  70.     if ok = 0 then return '<ERROR>'
  71.     if word(RenderOptions,5) = 0 then parse var rest '"'qpalette'"' rest
  72.     else qpalette = 'none'
  73.     if qrender = 1 then parse var rest Show_render rest
  74.     else Show_render = 'none'
  75.     parse var rest Strip_name '"'ext'"'
  76.  
  77.   end /* command */
  78.   else do
  79.     'REQUEST' '"The BatchConvert.ieb script does only'd2c(10)||,
  80.               'have settings for the first image."' '" OK "'
  81.     FileType = 'none'
  82.     qrender = 'none'
  83.     RenderOptions = 'none'
  84.     qpalette = 'none'
  85.     Show_render = 'none'
  86.     Strip_name = 'none'
  87.     ext = 'none'
  88.   end
  89.  
  90.   RenderOptions = translate(RenderOptions,'-',' ')
  91.   FileType = translate(FileType,'ª',' ')
  92.   qpalette = translate(qpalette,'ª',' ')
  93.  
  94.   back = '#'FileType '#'qrender '#'RenderOptions '#'qpalette '#'strip(Show_render) '#'strip(Strip_name) '#'strip(ext)
  95. return back
  96.  
  97. /* Required "Process_image" procedure  ------------------------------- */
  98.  
  99. process_image:
  100.   parse arg '"'src_image'"' '"'dst_image'"' '"'options'"'
  101.   parse var options '#'FileType '#'qrender '#'RenderOptions '#'qpalette '#'Show_render '#'Strip_name '#'ext .
  102.  
  103.   'OPEN' '"'src_image'"' '24'
  104.   if (RC ~= 0) then do
  105.     'IE_TO_FRONT'
  106.     'REQUEST' '"Failed to load image:' d2c(10)||src_image'"' '" OK "'
  107.     return '<ERROR>'
  108.   end
  109.   else LoadImage = result
  110.  
  111.   RenderOptions = strip(translate(RenderOptions,' ','-'))
  112.   FileType = strip(translate(FileType,' ','ª'))
  113.   qpalette = strip(translate(qpalette,' ','ª'))
  114.  
  115.   ext = '.'||strip(ext)
  116.   if strip(ext) = '.' then ext = ''
  117.  
  118.   /* Remove last non-number suffix */
  119.   if Strip_name = 1 then do
  120.     if datatype( get_ext(src_image) ,'N') then
  121.       src_image = get_base(get_base(src_image)) || '.'get_ext(src_image)
  122.     else
  123.       src_image = get_base(src_image)
  124.   end
  125.  
  126.   /* Set new name */
  127.   if datatype( get_ext(src_image) ,'N') then
  128.     dst_image = get_path(dst_image) || get_base(get_file(src_image)) || ext || '.'get_ext(src_image)
  129.   else
  130.     dst_image = get_path(dst_image) || get_file(src_image) || ext
  131.  
  132.   if (strip(qrender) = 1) then do
  133.     if word(RenderOptions,5) = 0 then 'PALETTE_LOAD' LoadImage '"'qpalette'"'
  134.     'RENDER_SET' LoadImage RenderOptions
  135.     If Show_render = 1 then 'RENDER' LoadImage
  136.     else 'RENDER' LoadImage 'QUIET'
  137.  
  138.     'SAVE' LoadImage '"'dst_image'"' '"'||filetype||'"'
  139.     if (RC ~= 0) then do
  140.       'REQUEST' '"Error when saving' LoadImage '!'LF,
  141.         'You have probably selected settings that are'LF,
  142.         'not possible to use with this file format."' '"Continue"'
  143.       return '<ERROR>'
  144.     end
  145.   end /* render image */
  146.   else do
  147.     'SAVE_DATA' LoadImage '"'dst_image'"' '"'||filetype||'"'
  148.     if (RC ~= 0) then do
  149.       'REQUEST' '"Error when saving' LoadImage '!'LF,
  150.         'You have probably selected settings that are'LF,
  151.         'not possible to use with this file format."' '"Continue"'
  152.       return '<ERROR>'
  153.     end
  154.   end
  155.  
  156.   'CLOSE' LoadImage
  157.  
  158.   back = 'OK'
  159. return back
  160.  
  161. /* Internal procedures  ---------------------------------------------- */
  162.  
  163. get_path:
  164.   parse arg get_path_in
  165.   if lastpos('/',get_path_in) ~= 0 then get_path_back = substr(get_path_in,1,lastpos('/',get_path_in))
  166.   else if lastpos(':',get_path_in) ~= 0 then get_path_back = substr(get_path_in,1,lastpos(':',get_path_in))
  167.   else get_path_back = ''
  168. return get_path_back
  169.  
  170. get_file:
  171.   parse arg get_file_in
  172.   if lastpos('/',get_file_in) ~= 0 then get_file_back = substr(get_file_in,1+lastpos('/',get_file_in))
  173.   else if lastpos(':',get_file_in) ~= 0 then get_file_back = substr(get_file_in,1+lastpos(':',get_file_in))
  174.   else get_file_back = get_file_in
  175. return get_file_back
  176.  
  177. get_ext:
  178.   parse arg get_ext_in
  179.   if lastpos('.',get_ext_in) ~= 0 then get_ext_back = substr(get_ext_in,1+lastpos('.',get_ext_in))
  180.   else get_ext_back = ''
  181. return get_ext_back
  182.  
  183. get_base:
  184.   parse arg get_base_in
  185.   if lastpos('.',get_base_in) ~= 0 then get_base_back = substr(get_base_in,1,lastpos('.',get_base_in)-1)
  186.   else get_base_back = get_base_in
  187. return get_base_back
  188.  
  189. /*******************************************************************/
  190. /* This is where control goes when an error code is returned by IE */
  191. /* It puts up a message saying what happened and on which line     */
  192. /*******************************************************************/
  193.  
  194. error:
  195. if RC=5 then do
  196.     IE_TO_FRONT
  197.     LAST_ERROR
  198.     'REQUEST "'||RESULT||'"'
  199. end
  200. else do
  201.     IE_TO_FRONT
  202.     LAST_ERROR
  203.     'REQUEST "Error detected!!!'||D2C(10)||'Image Engineer error message is as follows'||D2C(10)||result||D2C(10)||'Script failed on line '||SIGL||'"' 'Doh!'
  204. end
  205.  
  206. return '<ERROR>'
  207.